using B.S.Data.MES.API.Applications.BaseData.Command.SupplierCommand;
using B.S.Domain.BasicData.SupplierManagement;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.BaseData.CommandHandlers.SupplierCommandHandlers
{
    public class DeleSupplierCommandHandlers : IRequestHandler<DeleSupplierCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<Supplier> supplierRepository;

        public DeleSupplierCommandHandlers(IBaseRepository<Supplier> supplierRepository)
        {
            this.supplierRepository = supplierRepository;
        }

        public async Task<APIRequst<int>> Handle(DeleSupplierCommand request, CancellationToken cancellationToken)
        {
            var supplier = supplierRepository.GetAll().FirstOrDefault(x => x.SupplierId == request.SupplierId);
            
            supplier.isDel = true;
            await supplierRepository.Update(supplier);
            return new APIRequst<int>
            {
                Code = RequstCode.成功,
                Msg = RequstCode.成功.ToString()
            };
        }
    }
}